import { IFormSchemas, ITableColumns } from '@/type/table'
import { h } from 'vue'
import { ElLink } from 'element-plus'
import { MATTER_TITLE_WIDTH } from '@/plugins/const'

export enum EEventStatus {
  '待办理' = 1,
  '已办理',
}
import { EMatterTodoStatus } from '@/components/statusShow/util'
import MatterTodoShow from '@/components/statusShow/matterTodo/MatterTodoShow.vue'

const assignOptions = [
  {
    label: '待办理',
    value: EMatterTodoStatus['待办理'],
  },
  {
    label: '已办理',
    value: EMatterTodoStatus['已办理'],
  },
]

export enum ETaskType {
  '任务审批' = 1,
  '事项签收',
  '事项办理',
  '办理审核',
  '协调审核',
  '延期审核',
  '事项详情',
}

export enum ETaskBgColors {
  '#E3F9E9' = ETaskType['任务审批'],
  '#F2F3FF',
  '#FFF1E9',
  '#EBFAFC',
  '#F1EBFF',
  '#FCE8FB',
}

export enum ETaskColors {
  '#2BA471' = ETaskType['任务审批'],
  '#0052D9',
  '#D35A21',
  '#0C97B0',
  '#6C3ED6',
  '#AB26A4',
}

const taskTypeOptions = [
  {
    label: '任务审批',
    value: ETaskType['任务审批'],
  },
  {
    label: '事项签收',
    value: ETaskType['事项签收'],
  },
  {
    label: '事项办理',
    value: ETaskType['事项办理'],
  },
  {
    label: '办理审核',
    value: ETaskType['办理审核'],
  },
  {
    label: '协调审核',
    value: ETaskType['协调审核'],
  },
  {
    label: '延期审核',
    value: ETaskType['延期审核'],
  },
]

// 生成列表项
export function generateTableColumn(
  callback?: (columnType: string, row: Record<string, any>) => void,
) {
  const tableColumns: ITableColumns[] = [
    {
      label: 'ID',
      prop: 'id',
      width: 80,
    },
    {
      label: '事件标题',
      prop: 'title',
      minWidth: MATTER_TITLE_WIDTH,
      render: (row) => {
        return h(
          ElLink,
          {
            type: 'primary',
            underline: 'never',
            onClick: () => callback('title', row),
          },
          () => row.title,
        )
      },
    },
    {
      label: '事件类型',
      prop: 'type',
      minWidth: 150,
      render: (row) => {
        return h('span', ETaskType[row.type])
      },
    },
    {
      label: '状态',
      prop: 'status',
      width: 100,
      render: (row) => {
        return h(MatterTodoShow, {
          status: row.status,
        })
      },
    },
    {
      label: '创建时间',
      prop: 'creatTime',
      minWidth: 200,
    },
  ]
  return tableColumns
}

// 列表查询
export const searchSchame: IFormSchemas[] = [
  {
    label: '事件状态',
    prop: 'status',
    type: 'select',
    placeholder: '请选择事件状态',
    componentProps: {
      options: assignOptions,
      clearable: false,
    },
  },
  {
    label: '事件类型',
    prop: 'type',
    type: 'select',
    placeholder: '请选择事件类型',
    componentProps: {
      options: taskTypeOptions,
      clearable: true,
    },
  },
  {
    label: '事件标题',
    prop: 'title',
    type: 'input',
    placeholder: '请输入事件标题',
    componentProps: {
      maxlength: 50,
      clearable: true,
    },
  },
]
